<template>
    <div class="fund-group-setting">
        <div class="move-box">
            <RiskLeftModule
                v-model="inputValueLeft"
                @on-submit="submitInput"
                @on-handleNode="clickNode"
                :placeholders="ltitleName"
                :treeData="treeData"
                :leftHeight="leftHgt"
                :currentKey="2"
                :defaultExpandedKeys="defaultExpandedKeys"
            >
                <template slot="ltitle">账户组信息</template>
            </RiskLeftModule>
            <!-- 账户组信息 -->
            <template v-if="cutInfo === '本地' || cutInfo === '外部' || cutInfo === '动态账户组'">
                <RiskRightModule v-model="inputValueRight" :rightPlace="rtitleName" :rightHeight="leftHgt" @on-keyup="selectGroup">
                    <p slot="rtitle">账户组信息</p>
                    <span slot="button" class="dict-r-slot">
                        <el-select v-model="selectSourceType" placeholder="来源类型" size="mini" class="selectStyle" v-show="cutInfo === '外部'">
                            <el-option v-for="item in options" :key="item.value" :label="item.label" :value="item.value"> </el-option>
                        </el-select>
                        <el-button type="primary" size="mini" v-authCode.show="B_0003" @click="selectGroup">查询</el-button>
                    </span>
                    <span slot="button" class="dict-r-slot">
                        <el-button
                            type="primary"
                            size="mini"
                            v-authCode.show="B_0001"
                            v-show="cutInfo === '本地' || cutInfo === '动态账户组'"
                            @click="addGroup"
                            >新增</el-button
                        >
                    </span>
                    <span slot="button" class="dict-r-slot">
                        <el-button
                            type="danger"
                            size="mini"
                            v-authCode.show="B_0002"
                            v-show="cutInfo === '本地' || cutInfo === '动态账户组'"
                            @click="removeGroup"
                            >删除</el-button
                        >
                    </span>
                    <slot>
                        <div>
                            <el-table
                                :key="tableDataKey"
                                :data="tableData"
                                border
                                size="mini"
                                style="width: 100%"
                                :height="'calc(100vh - 198px)'"
                                @selection-change="handleSelectionChange"
                                @sort-change="handleSort"
                            >
                                <el-table-column type="selection" width="55" size="mini" align="center"> </el-table-column>
                                <el-table-column prop="fundGroupCode" label="账户组编码"> </el-table-column>
                                <el-table-column prop="fundGroupName" label="账户组名称" show-overflow-tooltip> </el-table-column>
                                <el-table-column prop="groupType" label="分组类型" show-overflow-tooltip v-if="cutInfo === '外部'">
                                    <template slot-scope="scope">
                                        <span>{{ groupTypeEnum[scope.row.groupType] || '--' }}</span>
                                    </template>
                                </el-table-column>
                                <el-table-column prop="sourceType" label="数据来源类型">
                                    <template slot-scope="scope">
                                        <span>{{ Dict.SourceType[scope.row.sourceType] }}</span>
                                    </template>
                                </el-table-column>
                                <el-table-column prop="operatorName" label="创建者" show-overflow-tooltip> </el-table-column>
                                <el-table-column prop="createDate" label="创建日期" show-overflow-tooltip align="center" sortable>
                                    <template slot-scope="scope">
                                        <span>{{ dateFormat(scope.row.createDate)}} {{ timeFormat(scope.row.createTime)}}</span>
                                    </template>
                                </el-table-column>
                                <el-table-column label="操作">
                                    <template slot-scope="scope">
                                        <RiskIconButton
                                            type="primary"
                                            icon="el-icon-view"
                                            v-authCode="B_0037"
                                            topTitle="查看账户组"
                                            @on-click="lookRow(scope.row)"
                                        ></RiskIconButton>
                                        <RiskIconButton
                                            type="primary"
                                            icon="el-icon-edit"
                                            v-authCode="B_0004"
                                            topTitle="编辑"
                                            @on-click="editRow(scope.row)"
                                            v-show="cutInfo != '外部'"
                                        ></RiskIconButton>
                                        <RiskIconButton
                                            type="danger"
                                            icon="el-icon-delete"
                                            v-authCode="B_0002"
                                            topTitle="删除"
                                            v-show="cutInfo != '外部'"
                                            @on-click="deleteRow(scope.row)"
                                        ></RiskIconButton>
                                    </template>
                                </el-table-column>
                            </el-table>
                        </div>
                        <div class="block">
                            <risk-pagination :paging="groupPage" @page-change="pageRet"></risk-pagination>
                        </div>
                    </slot>
                </RiskRightModule>

                <!-- 新增 -->
                <yh-dialog
                    :title="fundGroupDialog.title"
                    :visible.sync="fundGroupDialog.visible"
                    width="400px"
                    v-loading="loading"
                    drag
                    :close-on-click-modal="false"
                    :close-on-press-escape="false"
                >
                    <el-form label-width="110px" size="mini">
                        <el-form-item label="账户组代码">
                            <el-input placeholder="自动生成" style="width: 220px" disabled v-model="groupData.fundGroupCode"></el-input>
                        </el-form-item>
                        <el-form-item label="分组类型">
                            <el-input style="width: 220px" v-model="sourceType" disabled></el-input>
                        </el-form-item>
                        <el-form-item label="账户组名称">
                            <el-input
                                style="width: 220px"
                                v-model="groupData.fundGroupName"
                                :disabled="fundGroupDialog.title == '查看账户组'"
                            ></el-input>
                        </el-form-item>
                        <el-form-item label="创建者">
                            <el-input style="width: 220px" v-model="groupData.operatorName" disabled></el-input>
                        </el-form-item>
                        <el-form-item label="创建日期">
                            <el-input style="width: 220px" v-model="createDateshow" disabled></el-input>
                        </el-form-item>
                    </el-form>
                    <div slot="footer" class="dialog-footer">
                        <el-button size="mini" @click="fundGroupDialogClosed"> 取 消 </el-button>
                        <el-button size="mini" type="primary" @click="fundGroupDialogConfirm" v-show="fundGroupDialog.action != 0"> 确 定 </el-button>
                    </div>
                </yh-dialog>
            </template>

            <!-- 账户组内基本信息 -->
            <template v-else>
                <RiskRightModule v-model="inputDetailValueRight" :rightPlace="right2Place" :rightHeight="leftHgt">
                    <p slot="rtitle">账户组内基本信息</p>
                    <span slot="button" class="dict-r-slot">
                        <el-button type="primary" size="mini" v-authCode.show="B_0007" @click="selectDetail">查询</el-button>
                    </span>
                    <span slot="button" class="dict-r-slot">
                        <el-button type="primary" v-show="false" size="mini" disabled @click="editDetail">编辑</el-button>
                        <!-- 这里弄一个虚假按钮不显示，不然disabled属性加不上 -->
                        <el-button
                            v-show="currentData.sourceType === '1'"
                            type="primary"
                            size="mini"
                            v-authCode.show="B_0004"
                            :disabled="isEditDisabled"
                            @click="editDetail"
                            >编辑</el-button
                        >
                    </span>
                    <span slot="button" class="dict-r-slot">
                        <el-button
                            type="danger"
                            size="mini"
                            v-authCode.show="B_0006"
                            @click="removeDetail"
                            v-show="currentData.sourceType === '1' && !currentData.dynamicType"
                            >删除</el-button
                        >
                    </span>
                    <slot>
                        <div>
                            <el-table
                                :data="tableData"
                                border
                                size="mini"
                                style="width: 100%"
                                :height="'calc(100vh - 198px)'"
                                @selection-change="handleSelectionDetailChange"
                                key="1"
                                @sort-change="handleSort2"
                            >
                                <el-table-column type="selection" width="40" size="mini" align="center"> </el-table-column>
                                <el-table-column prop="fundCode" label="产品代码" show-overflow-tooltip> </el-table-column>
                                <el-table-column prop="fundName" label="产品名称" min-width="100" show-overflow-tooltip :formatter="formatter">
                                </el-table-column>
                                <el-table-column prop="fundNameSt" label="产品简称" show-overflow show-overflow-tooltip :formatter="formatter">
                                </el-table-column>
                                <el-table-column
                                    prop="fundProductCode"
                                    label="对外产品代码"
                                    min-width="110px"
                                    show-overflow-tooltip
                                    :formatter="formatter"
                                >
                                </el-table-column>
                                <el-table-column prop="depositaryName" label="受托人" show-overflow-tooltip :formatter="formatter"> </el-table-column>
                                <el-table-column prop="fundType" label="产品类型" :formatter="handleFundType" show-overflow-tooltip>
                                </el-table-column>
                                <el-table-column prop="localCustodian" label="托管人" min-width="110px" show-overflow-tooltip :formatter="formatter">
                                </el-table-column>
                                <el-table-column prop="period" label="产品所属期" min-width="120px" show-overflow-tooltip>
                                    <template slot-scope="scope">
                                        {{ getTrans(scope.row.period, 'period') }}
                                    </template>
                                </el-table-column>
                                <el-table-column prop="operateType" label="产品运作方式" min-width="110px" show-overflow-tooltip>
                                    <template slot-scope="scope">
                                        {{ getTrans(scope.row.operateType, 'operateType') }}
                                    </template>
                                </el-table-column>
                                <el-table-column prop="investObject" label="产品投资对象" min-width="110px" show-overflow-tooltip>
                                    <template slot-scope="scope">
                                        {{ getTrans(scope.row.investObject, 'investObject') }}
                                    </template>
                                </el-table-column>
                                <el-table-column prop="investTarget" label="产品投资目标" min-width="110px" show-overflow-tooltip>
                                    <template slot-scope="scope">
                                        {{ getTrans(scope.row.investTarget, 'investTarget') }}
                                    </template>
                                </el-table-column>
                                <el-table-column prop="trusteeDuty" label="产品投资理念" min-width="110px" show-overflow-tooltip>
                                    <template slot-scope="scope">
                                        {{ getTrans(scope.row.trusteeDuty, 'trusteeDuty') }}
                                    </template>
                                </el-table-column>
                                <el-table-column prop="raiseType" label="产品募集对象" min-width="110px" show-overflow-tooltip>
                                    <template slot-scope="scope">
                                        {{ getTrans(scope.row.raiseType, 'raiseType') }}
                                    </template>
                                </el-table-column>
                                <el-table-column prop="openDate" label="成立日期" min-width="100px" :formatter="formatterDate" align="center" sortable>
                                </el-table-column>
                                <el-table-column prop="contractEndDate" label="到期日期" min-width="100px" :formatter="formatterDate" align="center" sortable>
                                </el-table-column>
                            </el-table>
                        </div>
                        <div class="block">
                            <risk-pagination :paging="detailPage" @page-change="detailPageChange"></risk-pagination>
                        </div>
                    </slot>
                </RiskRightModule>
                <!-- 编辑 -->
                <div>
                    <yh-dialog
                        title="编辑账户组内基本信息"
                        :visible.sync="editLocalDialog.visible"
                        class="editDialog"
                        width="800px"
                        v-loading="loading"
                        drag
                        :close-on-click-modal="false"
                        :close-on-press-escape="false"
                    >
                        <div style="height: fit-content">
                            <RiskTrantable
                                leftPlaceholder="编号/名称"
                                rightPlaceholder="编号/名称"
                                :leftColumns="tranColumns"
                                :rightColumns="tranColumns"
                                :leftTableData="leftTranData"
                                :rightTableData="rightTranData"
                                :leftSearchNames="['fundCode', 'fundName']"
                                indexKey="fundCode"
                                ref="tranTable"
                                sort="fundName"
                            />
                        </div>
                        <div slot="footer" class="dialog-footer">
                            <el-button size="mini" @click="editLocalDialogClosed"> 取 消 </el-button>
                            <el-button size="mini" type="primary" @click="editLocalDialogConfirm">确 定 </el-button>
                        </div>
                    </yh-dialog>
                </div>
                <!-- 查看产品详情 -->
                <div>
                    <yh-dialog
                        drag
                        :title="lookFundDialog.title"
                        :visible.sync="lookFundDialog.visible"
                        v-loading="loading"
                        :close-on-click-modal="false"
                        :close-on-press-escape="false"
                    >
                        <el-form label-width="120px" size="mini">
                            <el-row>
                                <el-col :span="12">
                                    <el-form-item label="产品代码">
                                        <el-input style="width: 160px" v-model="detailData.fundCode" readonly></el-input>
                                    </el-form-item>
                                    <el-form-item label="产品简称">
                                        <el-input style="width: 160px" v-model="detailData.fundNameSt" readonly></el-input>
                                    </el-form-item>
                                    <el-form-item label="产品类型">
                                        <el-input style="width: 160px" v-model="fundType" readonly></el-input>
                                    </el-form-item>
                                    <el-form-item label="对外产品代码">
                                        <el-input style="width: 160px" v-model="detailData.fundProductCode" readonly></el-input>
                                    </el-form-item>
                                </el-col>
                                <el-col :span="10">
                                    <el-form-item label="产品名称">
                                        <el-input style="width: 160px" v-model="detailData.fundName" readonly></el-input>
                                    </el-form-item>
                                    <el-form-item label="产品英文名称">
                                        <el-input style="width: 160px" v-model="detailData.fundNameEn" readonly></el-input>
                                    </el-form-item>
                                    <el-form-item label="产品状态">
                                        <el-input style="width: 160px" v-model="fundStatus" readonly></el-input>
                                    </el-form-item>
                                    <el-form-item label="币种编码">
                                        <el-input style="width: 160px" v-model="detailData.curCode" readonly></el-input>
                                    </el-form-item>
                                </el-col>
                            </el-row>
                        </el-form>
                        <div slot="footer" class="dialog-footer">
                            <el-button size="mini" @click="lookFundDialog.visible = false"> 取 消 </el-button>
                        </div>
                    </yh-dialog>
                </div>
            </template>
        </div>
        <!-- 删除 -->
        <yh-dialog
            drag
            :title="removeDialog.title"
            :visible.sync="removeDialog.visible"
            width="500px"
            :close-on-click-modal="false"
            :close-on-press-escape="false"
        >
            <div class="remove-text">
                <!-- <span v-for="(itme, index) in delPendingData" :key="index"> {{ itme }} , </span> -->
                <p>{{ delPendingData.join(',') }}</p>
            </div>
            <div slot="footer" class="dialog-footer">
                <el-button size="mini" @click="removeDialogClosed"> 取 消 </el-button>
                <el-button size="mini" type="primary" @click="removeDialogConfirm">确 定 </el-button>
            </div>
        </yh-dialog>
        <yh-dialog
            drag
            :title="dynamicGroupEditDialog.title"
            :visible.sync="dynamicGroupEditDialog.visible"
            width="800px"
            v-loading="loading"
            :close-on-click-modal="false"
            :close-on-press-escape="false"
            v-if="dynamicGroupEditDialog.visible"
        >
            <BoundCfg0
                :stockBound="stockBound"
                investGroupType="0"
                operateType="edit"
                operatePanelHeight="40vh"
                @onHandleOperateOver="onHandleOperateOver"
                v-if="dynamicGroupEditDialog.visible"
            ></BoundCfg0>
            <div slot="footer" class="dialog-footer">
                <el-button size="mini" @click="editDynamincDialogClosed"> 取 消 </el-button>
                <el-button size="mini" type="primary" @click="editDynamicDialogConfirm">确 定 </el-button>
            </div>
        </yh-dialog>
    </div>
</template>
<script lang="ts">
import RiskIconButton from '@/common/components/risk-icon-button.vue';
import RiskLeftModule from '@/common/components/risk-left-module.vue';
import RiskRightModule from '@/common/components/risk-right-module.vue';
import RiskTrantable from '@/common/components/risk-trantable.vue';
import { getCurrentPageData, dateFormat, formatterDate, formatterTime, formatter, formatterNumber, timeFormat } from '@/utils/tools';
import { DialogVO } from '@yhfin/biz';
import { Component, Vue } from 'vue-property-decorator';
import { getUser } from '@/utils/user-util';
import XEUtils from 'xe-utils';
import Dict from '../dict/index';
import DictionConstUtil, { SET_CACHE, SGU_CACHE } from '@/utils/diction-const-util';
import BoundCfg0 from '../fund-group-setting/BoundCfg0.vue';
import RiskCustomSelect from '@/common/components/risk-custom-select.vue';
import RiskPagination from '@/common/components/risk-pagination.vue';
export interface pages {
    total?: number;
    pageSize?: number;
    currentPage?: number;
}

@Component({
    name: 'FundGroupInfo',
    components: {
        RiskLeftModule,
        RiskRightModule,
        RiskIconButton,
        RiskTrantable,
        BoundCfg0,
        RiskCustomSelect,
        RiskPagination,
    },
})
export default class FundGroupInfo extends Vue {
    formatterDate = formatterDate;
    formatterTime = formatterTime;
    timeFormat = timeFormat;
    formatter = formatter;
    formatterNumber = formatterNumber;
    dateFormat = dateFormat;
    private inputValueLeft: string = '';
    private ltitleName: string = '编号/名称';
    private leftHgt: string = 'calc(100vh - 64px) ';
    private inputValueRight: string = '';
    private inputDetailValueRight: string = '';
    private rtitleName: string = '账户组编码/名称';
    private right2Place: string = '编号/名称';

    private sourceType: string = '';
    private fundType: string = ''; // 产品类型
    private fundStatus: string = ''; // 产品状态
    private cutInfo: string = '外部';
    private tableData: any = [];
    private tableDataKey = 0;
    private tableDataList: any = [];
    private tableDataSearched: any[] = [];
    private tableDataLocal: any = [];
    private tableDataDynamic: any = [];
    private tableDataOutside: any = [];
    private currentData: any = {};

    private stockBound: any[] = []; // 范围属性组集合
    private stockBoundTemp: any[] = [];
    private fundGroupDialog: DialogVO = new DialogVO();
    private removeDialog: DialogVO = new DialogVO();
    private editLocalDialog: DialogVO = new DialogVO();
    private lookFundDialog: DialogVO = new DialogVO();
    private dynamicGroupEditDialog: DialogVO = new DialogVO();
    Dict: any = new Dict();
    private hasSelectedData: any[] = [];
    private delPendingData: any[] = [];
    private FundTypes: any = [];
    private leftTranData: any[] = [];
    private rightTranData: any[] = [];
    private tranColumns: any[] = [
        {
            label: '编号',
            prop: 'fundCode',
            width: 80,
        },
        {
            label: '名称',
            prop: 'fundName',
            width: 165,
        },
    ];

    private groupPage: pages = {
        currentPage: 1,
        pageSize: 50,
        total: 0,
    };

    private detailPage: pages = {
        currentPage: 1,
        pageSize: 50,
        total: 0,
    };

    private options: any[] = [
        {
            value: '',
            label: '全部',
        },
        {
            value: '2',
            label: '恒生-主动',
        },
        {
            value: '5',
            label: '恒生-被动',
        },
    ];

    private treeData: any = [
        {
            label: '本地',
            id: 1,
            children: [],
        },
        {
            label: '外部',
            id: 2,
            children: [],
        },
        {
            label: '动态账户组',
            id: 3, //
            children: [],
        },
    ];
    private groupData: any = {
        fundGroupCode: '自动生成',
        sourceType: '1',
        fundGroupName: '',
        operatorName: getUser().userNickName,
        createDate: XEUtils.toDateString(new Date(), 'yyyyMMdd'),
        dynamicType: 0,
    };
    createDateshow: any = XEUtils.toDateString(new Date(), 'yyyy-MM-dd');

    private detailData: any = {
        fundCode: '',
        fundNameSt: '',
        sourceType: '',
        fundProductCode: '',
        fundName: '',
        fundNameEn: '',
        fundStatus: '',
        curCode: '',
    };

    private selectSourceType: string = ''; // 来源类型(外部)

    private isGroup: boolean = true; // 为分组

    private defaultExpandedKeys: any[] = [2]; // 默认展开

    private investTargetTypes: any[] = [];

    private groupTypes: any;

    private groupTypeEnum: any = {};
    isEditDisabled: boolean = false; // 表格上方编辑按钮是否禁用

    async mounted() {
        this.groupTypes = (await this.getGroupTypes()) || [];
        this.groupTypeEnum = DictionConstUtil.ListToPojo3('groupType', this.groupTypes, 'groupTypeFullName');
        this.FundTypes = await SGU_CACHE('FundType', '/dict/list/code/Y_000002', []);
        // 产品投资目标
        this.investTargetTypes = await SGU_CACHE('investTargetType', '/dict/list/code/Y_000202', []);
        this.getFundGroupInfo();
    }

    // 获取外部分组类型
    private getGroupTypes() {
        return new Promise((resolve, reject) => {
            this.$axios({ method: 'get', url: '/fundGroup/queryFundGroupType' })
                .then((res: any) => {
                    res.forEach(element => {
                        element.label = element.groupTypeFullName;
                        element.id = element.groupType + '-groupType';
                        element.children = [];
                    });
                    resolve(res);
                })
                .catch(err => {
                    reject(err);
                });
        });
    }

    // 获取账户组数据
    private getFundGroupInfo(): void {
        // 传false,默认展示全部，不传（默认true），会排除掉导出类型为不导出的那些外部产品组
        this.$axios.post('/fundGroup/list?filterNoImportType=false').then((res: any) => {
            SET_CACHE('FundGroup', res);
            var local = [];
            var outside = [];
            let disk = [];
            let Sans = [];
            for (let item of res) {
                if (item.sourceType === '1') {
                    disk.push(item);
                    let datas = item.fundGroupCode + '-' + item.fundGroupName;
                    local.push(Object.assign(item, { label: datas, id: item.fundGroupCode }));
                } else {
                    Sans.push(item);
                    let datas = item.fundGroupCode + '-' + item.fundGroupName;
                    outside.push(Object.assign(item, { label: datas, id: item.fundGroupCode }));
                }
            }
            this.treeData[0].children = local.filter(item => !item.dynamicType);
            this.treeData[2].children = local.filter(item => item.dynamicType);
            this.treeData[1].children = this.packageOutsideTree(outside);
            this.tableDataLocal = disk.filter(item => !item.dynamicType);
            this.tableDataDynamic = disk.filter(item => item.dynamicType);
            this.tableDataOutside = Sans;
            this.getTableGroupData();
        });
    }

    // 外部树组装
    private packageOutsideTree(outside): any[] {
        if (this.groupTypes.length) {
            let noFatherArr = outside.filter(item => !item.groupType);
            this.groupTypes.forEach(element => {
                element.children = outside.filter(item => item.groupType === element.groupType);
            });

            return [...this.groupTypes, ...noFatherArr];
        }
        return outside;
    }

    private getTableGroupData(): void {
        if (this.cutInfo == '本地') {
            this.tableDataList = this.tableDataLocal;
        } else if (this.cutInfo == '动态账户组') {
            this.tableDataList = this.tableDataDynamic;
        } else {
            this.tableDataList = this.tableDataOutside;
        }
        this.selectGroup();
    }

    // 左侧查询
    private submitInput(): void {}

    // 右侧查询
    private selectGroup(): void {
        this.tableDataSearched = this.handleFilter(this.tableDataList, this.inputValueRight, 'fundGroupCode', 'fundGroupName');
        if (this.cutInfo === '外部') {
            this.tableDataSearched = this.tableDataSearched.filter(item => {
                return item.sourceType === this.selectSourceType || this.selectSourceType === '';
            });
        }
        this.groupPage.currentPage = 1;
        this.pageRet();
    }

    // 账户组筛选数据
    private handleFilter(dataSource: any, param: any, code: string, name: string): any {
        if (!param || !dataSource) {
            return dataSource;
        } else {
            return dataSource.filter((item: any) => {
                return (
                    (item[name] || '').toUpperCase().includes(param.toUpperCase()) || (item[code] || '').toUpperCase().includes(param.toUpperCase())
                );
            });
        }
    }

    // 删除账户组
    private removeGroup(): void {
        if (this.hasSelectedData.length < 1) {
            this.yh_message_warn('未选择删除项');
        } else {
            this.delPendingData = this.hasSelectedData;
            this.removeDialog = this.removeDialog.getDeleteDialog('确定删除账户组？');
        }
    }

    // 确认删除
    private removeDialogConfirm(): void {
        if (this.isGroup) {
            // 账户组删除
            this.$axios({
                url: '/fundGroup/delete/codes',
                method: 'DELETE',
                data: this.delPendingData,
            }).then((res: any) => {
                this.yh_message_success('删除成功');
                this.getFundGroupInfo();
                this.removeDialogClosed();
            });
        } else {
            // 账户组下基金删除
            this.$axios({
                url: '/fundInfo/delete/codes/' + this.currentData.id,
                method: 'DELETE',
                data: this.delPendingData,
            }).then((res: any) => {
                this.yh_message_success('删除成功');
                this.getQueryList(this.currentData.id);
                this.removeDialogClosed();
            });
        }
        this.hasSelectedData = [];
    }

    // 关闭删除
    private removeDialogClosed(): void {
        this.removeDialog.visible = false;
    }

    // 账户组勾选
    private handleSelectionChange(data: any[]): void {
        this.hasSelectedData = XEUtils.map(data, item => item.fundGroupCode);
    }

    // 基金明细勾选
    private handleSelectionDetailChange(data: any[]): void {
        this.hasSelectedData = XEUtils.map(data, item => item.fundCode);
    }

    // 新增账户组
    private addGroup(): void {
        this.groupData.fundGroupName = '';
        this.groupData.operatorName = getUser().userNickName;
        this.groupData.createDate = XEUtils.toDateString(new Date(), 'yyyyMMdd');
        this.createDateshow = XEUtils.toDateString(new Date(), 'yyyy-MM-dd');
        this.sourceType = this.Dict.SourceType[this.groupData.sourceType];
        this.fundGroupDialog = this.fundGroupDialog.getAddDialog('新增账户组');
    }

    // 确认账户组
    private fundGroupDialogConfirm(): void {
        if (!this.groupData.fundGroupName) {
            this.yh_message_error('账户组名称不能为空');
            return;
        }
        this.groupData.dynamicType = this.currentData.label === '动态账户组' ? 1 : 0;
        if (this.fundGroupDialog.action === 1) {
            this.$axios
                .post('/fundGroup/insert', this.groupData)
                .then((res: any) => {
                    this.yh_message_success('新增成功');
                    this.getFundGroupInfo();
                    this.fundGroupDialogClosed();
                })
                .catch(() => {
                    this.yh_message_error('新增失败');
                });
        } else {
            this.$axios
                .post('/fundGroup/update', this.groupData)
                .then((res: any) => {
                    this.yh_message_success('更新成功');
                    this.getFundGroupInfo();
                    this.fundGroupDialogClosed();
                })
                .catch(() => {
                    this.yh_message_error('更新失败');
                });
        }
    }

    private fundGroupDialogClosed(): void {
        this.fundGroupDialog.visible = false;
    }

    // 查看账户组
    private lookRow(row: any): void {
        // createDateshow: any = XEUtils.toDateString(new Date(), 'yyyy-MM-dd');
        this.createDateshow = dateFormat(row.createDate);
        this.groupData = JSON.parse(JSON.stringify(row));
        this.sourceType = this.Dict.SourceType[this.groupData.sourceType];
        this.fundGroupDialog = this.fundGroupDialog.getSeeDialog('查看账户组');
    }

    // 编辑账户组
    private editRow(row: any): void {
        this.createDateshow = dateFormat(row.createDate);
        this.groupData = JSON.parse(JSON.stringify(row));
        this.sourceType = this.Dict.SourceType[this.groupData.sourceType];
        this.fundGroupDialog = this.fundGroupDialog.getUpdateDialog('编辑账户组');
    }

    // 删除账户组
    private deleteRow(row: any): void {
        this.delPendingData = [row.fundGroupCode];
        this.removeDialog = this.removeDialog.getDeleteDialog('确定删除账户组？');
    }

    // 分页
    private pageRet(): void {
        if (this.inputValueRight || (this.selectSourceType && this.cutInfo === '外部')) {   
            this.groupPage.total = this.tableDataSearched.length;
            this.tableData = getCurrentPageData(this.tableDataSearched, this.groupPage.currentPage, this.groupPage.pageSize);
        } else {
            this.groupPage.total = this.tableDataList.length;
            this.tableData = getCurrentPageData(this.tableDataList, this.groupPage.currentPage, this.groupPage.pageSize);
        }
    }

    private detailPageChange(): void {
        if (this.inputDetailValueRight) {
            this.detailPage.total = this.tableDataSearched.length;
            this.tableData = getCurrentPageData(this.tableDataSearched, this.detailPage.currentPage, this.detailPage.pageSize);
        } else {
            this.detailPage.total = this.tableDataList.length;
            this.tableData = getCurrentPageData(this.tableDataList, this.detailPage.currentPage, this.detailPage.pageSize);
        }
    }

    // 左边栏选择节点
    private clickNode(data: any): void {
        this.cutInfo = data.label;
        this.currentData = data;
        if (String(this.currentData.id).indexOf('FT_') !== -1) {
            this.isEditDisabled = true;
        } else {
            this.isEditDisabled = false;
        }

        if (data.hasOwnProperty('children')) {
            this.isGroup = true;
            if (data.groupTypeFullName) {
                // 有分类时 默认外部
                this.cutInfo = '外部';
                this.tableDataList = this.tableDataOutside.filter(item => item.groupType === data.groupType);
                this.selectGroup();
            } else {
                this.getTableGroupData();
            }
        } else {
            this.isGroup = false;
            this.getQueryList(data.id);
        }
    }

    // 基金明细
    private getQueryList(id: string): void {
        this.$axios.get('fundGroup/getRelationFund/' + id).then((res: any) => {
            this.tableDataList = res;
            this.selectDetail();
        });
    }

    // 基金信息查询
    private selectDetail(): void {
        this.tableDataSearched = this.handleFilter(this.tableDataList, this.inputDetailValueRight, 'fundCode', 'fundName');
        this.detailPage.currentPage = 1;
        this.detailPageChange();
    }

    // 基金信息编辑
    private editDetail(): void {
        if (!this.currentData.dynamicType) {
            this.rightTranData = this.tableDataList;
            const fundCodes = XEUtils.map(this.tableDataList, item => item.fundCode);
            // 本地
            this.editLocalDialog = this.editLocalDialog.getAddDialog('');
            this.$axios.get('/fundInfo/list').then((res: any) => {
                let needData = res;
                let retData = [];
                for (let i = 0; i < needData.length; i++) {
                    if (!fundCodes.includes(needData[i].fundCode)) {
                        needData[i].id = needData[i].fundCode;
                        retData.push(needData[i]);
                    }
                }
                this.leftTranData = retData;
            });
        } else {
            // 动态账户组
            this.$axios.get('/fundDynamicGroupConfig/getConfig/code/' + this.currentData.id).then((res: any) => {
                this.stockBound = res;
                this.dynamicGroupEditDialog = this.dynamicGroupEditDialog.getAddDialog('编辑账户组配置');
            });
        }
    }

    // 编辑
    private editLocalDialogConfirm(): void {
        let fundCodelist = [];
        const rightData = (this.$refs.tranTable as any).getRightAllData();
        rightData.map((item: any) => {
            fundCodelist.push(item.fundCode);
        });
        this.$axios
            .post('/fundInfo/insert/codes/' + this.currentData.id, fundCodelist)
            .then(res => {
                this.getQueryList(this.currentData.id);
                this.editLocalDialogClosed();
                this.yh_message_success('添加成功');
            })
            .catch(() => {
                // this.loading = false;
            });
    }

    private editLocalDialogClosed(): void {
        this.rightTranData = [];
        this.editLocalDialog.visible = false;
    }

    // 基金信息删除
    private removeDetail(): void {
        if (this.hasSelectedData.length < 1) {
            this.yh_message_warn('未选择删除项!');
        } else {
            this.delPendingData = this.hasSelectedData;
            this.removeDialog = this.removeDialog.getDeleteDialog('确认删除账户组下基金？');
        }
    }

    // 查看基金信息
    private lookFundRow(row: any): void {
        this.lookFundDialog = this.lookFundDialog.getSeeDialog('产品详情');
        this.$axios.get('/fundInfo/fund/detail/' + row.fundCode).then((res: any) => {
            this.detailData = res;
            this.fundType = this.handleFundType(res);
            this.fundStatus = this.Dict.fundStatus[res.fundStatus];
        });
    }

    // 转换产品类型
    private handleFundType({ fundType }): string {
        let ret: string = '';
        (this.FundTypes || []).forEach(item => {
            if (item.dictKey === fundType) {
                ret = item.dictKeyName;
                return;
            }
        });
        return ret;
    }

    // 动态编辑返回值
    private onHandleOperateOver(value: any): void {
        if (value.length > 0) {
            value.forEach(item => {
                this.$set(item, 'dynamicGroupCode', this.currentData.id);
            });
            this.stockBoundTemp = value;
        } else {
            this.stockBoundTemp = [];
            this.yh_message_warn('删除全部配置将会是无效操作,如有必要,可直接该删除账户组');
        }
    }

    // 确认编辑
    private editDynamicDialogConfirm(): void {
        this.$axios.post('/fundDynamicGroupConfig/saveConfigs', this.stockBoundTemp).then(res => {
            this.yh_message_success('编辑成功');
            this.getQueryList(this.currentData.id);
            this.editDynamincDialogClosed();
        });
    }

    private editDynamincDialogClosed(): void {
        this.dynamicGroupEditDialog.visible = false;
    }
    // 字段转换
    private getTrans(value, type): string {
        if (type == 'period') {
            switch (value) {
                case '0':
                    return '开放期';
                case '1':
                    return '封闭期';
                case '2':
                    return '建仓期';
                default:
                    return '--';
            }
        } else if (type == 'investTarget') {
            let data = this.investTargetTypes.find(item => item.dictKey == value);
            let retValue = data ? data.dictKeyName : '';
            return retValue || '--';
        } else if (type == 'operateType') {
            switch (value) {
                case '1':
                    return '开放式基金';
                case '2':
                    return '封闭式基金';
                case '3':
                    return '定开基金';
                case '4':
                    return 'ETF基金';
                case '5':
                    return 'LOF基金';
                case '6':
                    return 'ETF联接基金';
                default:
                    return '--';
            }
        } else if (type == 'investObject') {
            switch (value) {
                case '1':
                    return '股票型';
                case '2':
                    return '债券型';
                case '3':
                    return '货币型';
                case '4':
                    return '混合型';
                case '5':
                    return 'FOF基金';
                case '6':
                    return 'MOM基金';
                case '7':
                    return '指数型基金';
                default:
                    return '--';
            }
        } else if (type == 'trusteeDuty') {
            switch (value) {
                case '1':
                    return '主动型';
                case '2':
                    return '被动型';
                case '3':
                    return '主被动型';
                default:
                    return '--';
            }
        } else if (type == 'raiseType') {
            switch (value) {
                case '0':
                    return '集合计划';
                case '1':
                    return '公募基金';
                case '2':
                    return '私募基金';
                case '3':
                    return '专户基金';
                case '4':
                    return '社保基金';
                case '5':
                    return '基金养老基金';
                case '6':
                    return '企业年金基金';
                case '7':
                    return '职业年金基金';
                case '8':
                    return '养老金产品基金';
                case '9':
                    return '单一资产管理计划';
                default:
                    return '--';
            }
        }
    }
    handleSort(column): void {
        this.groupPage.currentPage = 1;
        if (column.order == 'ascending') {
            if (this.inputValueRight || (this.selectSourceType && this.cutInfo === '外部')) {
                this.tableDataSearched.sort(this.dateData('createDate', true))
                this.tableData = getCurrentPageData(this.tableDataSearched, this.groupPage.currentPage, this.groupPage.pageSize);    
            } else {
                this.tableDataList.sort(this.dateData('createDate', true))
                this.tableData = getCurrentPageData(this.tableDataList, this.groupPage.currentPage, this.groupPage.pageSize);
            }
        } else {
            if (this.inputValueRight || (this.selectSourceType && this.cutInfo === '外部')) {
                this.tableDataSearched.sort(this.dateData('createDate', true)).reverse()
                this.tableData = getCurrentPageData(this.tableDataSearched, this.groupPage.currentPage, this.groupPage.pageSize);    
            } else {
                this.tableDataList.sort(this.dateData('createDate', true)).reverse()
                this.tableData = getCurrentPageData(this.tableDataList, this.groupPage.currentPage, this.groupPage.pageSize);
            }
        }
    }
    handleSort2(column): void {
        this.groupPage.currentPage = 1;
        if (column.order == 'ascending') {
            if (this.inputDetailValueRight) {
                this.tableDataSearched.sort(this.dateData(column.prop, true))
                this.tableData = getCurrentPageData(this.tableDataSearched, this.detailPage.currentPage, this.detailPage.pageSize);
            } else {
                this.tableDataList.sort(this.dateData(column.prop, true))
                this.tableData = getCurrentPageData(this.tableDataList, this.detailPage.currentPage, this.detailPage.pageSize);
            }
        } else {
            if (this.inputDetailValueRight) {
                this.tableDataSearched.sort(this.dateData(column.prop, true)).reverse()
                this.tableData = getCurrentPageData(this.tableDataSearched, this.detailPage.currentPage, this.detailPage.pageSize);
            } else {
                this.tableDataList.sort(this.dateData(column.prop, true)).reverse()
                this.tableData = getCurrentPageData(this.tableDataList, this.detailPage.currentPage, this.detailPage.pageSize);
            }
        }
    }
    dateData(property, bol) {
        return function(a, b) {
            var value1 = a[property];
            var value2 = b[property];
            if (bol) {
            // 升序
                return Date.parse(value1) - Date.parse(value2);
            } else {
            // 降序
                return Date.parse(value2) - Date.parse(value1)
            }
        }
    }
}
</script>
<style lang="scss" scoped>
.fund-group-setting {
    position: relative;
    height: 100%;
    .selectStyle {
        width: 160px;
        margin-right: 10px;
    }
    .dict-r-slot {
        margin-left: 10px;
    }

    & /deep/ .el-dialog .el-dialog__body {
        max-height: 100vh;
    }
}

/deep/ .editDialog .el-dialog .el-dialog__body {
    height: 460px;
}
/deep/ .el-table--border::after,
.el-table--group::after {
    width: 0 !important;
    height: 0 !important;
}
/deep/ .el-table--border th:first-child .cell {
    padding-left: 6px;
}
</style>
